//获取时间工具
let dateshijian = new Date();
    console.log(dateshijian);
  //获取天数
    function getDangDayTianShu(year ,month){
      return new Date(year,month,0).getDate()
    }
    // 根据天数遍历每一天返回此数组渲染日历
    function getArrday(firstday,days){
      //周三=3
        let arr =new Array();
        // console.log();
      for(let i=1;i<=days;i++){
        if(i<=firstday){
          let riqiobject={riqi_id:i,style:"0",emoimg_id:"0",emotext:""}
          arr.push(riqiobject)
          arr.unshift(88)
        }else{
          let riqiobject={riqi_id:i,style:"0",emoimg_id:"0",emotext:"",list_id:''}
          arr.push(riqiobject)
        }
      }
      if(arr.length!=42){
          let s = 42-arr.length
          for (let i=0 ; i<s;i++) {
              arr.push(88) 
          }
      }
      return arr
    }
    // 获取当前年月日
    function getDangQianRiQi(){
    let shijian = new Date();
    // 获取当前年月日
    let day = shijian.getDate();
    // console.log(day);
    //0-11月的值
    let month = shijian.getMonth()+1;
    let year = shijian.getFullYear();
    //获取周几
    let week=new Date(year,month-1,1).getDay()
    // 获取当前有多少天

    let arr=getArrday(week,getDangDayTianShu(year,month))
    let time = {nian:year,yue:month,ri:day,zhouji:week,dangyuearr:arr}
    return time;
  }
  // 下个月
  function xiageDays(y , m){
    // 获取指定月多少天
    let days= getDangDayTianShu(y,m)
    //获取周几
    let week=new Date(y,m-1,1).getDay()
    // console.log(y+"年"+m+"月"+"周"+week);
    let time = {nian:y,yue:m,tianshu:days,zhouji:week}
    // 根据天数渲染数组
    // getDangDayTianShu()
    return time;
  }
// 根据年月获取日期对象
function shanggeDays(y , m){
  // 获取指定月多少天
  let days= getDangDayTianShu(y,m)
  //获取周几
  // console.log(m+"jiyue---------------");
  let week=new Date(y,m-1,1).getDay()
  // console.log(y+"年"+m+"月"+"周"+week);
  let arr=getArrday(week,getDangDayTianShu(y,m))
  let time = {nian:y,yue:m,tianshu:days,zhouji:week ,dangyuearr:arr}
  // 根据天数渲染数组
  // getDangDayTianShu()
  return time;
}
//格式化时间
function formatDatetime(date) {
  function padZero(num) {
      return num < 10 ? '0' + num : num;
  }
  let year = date.getFullYear();
  let month = padZero(date.getMonth() + 1);
  let day = padZero(date.getDate());
  let hours = padZero(date.getHours());
  let minutes = padZero(date.getMinutes());
  let seconds = padZero(date.getSeconds());
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
//格式化时间没有几点
function formatDate(date) {
 let yyyy=date.nian;
 let mm = date.yue;
 let dd = date.ri;
 dd=dd.length==1?+dd:'0'+dd
//  console.log(dd);
  return `${yyyy}-${mm}-${dd}`;
}
 
function padZero(value) {
  return value < 10 ? `0${value}` : value;
}
//导出需要的属性
// 时间对象
const time=getDangQianRiQi();
//日历数组
const arr = getArrday(time.zhouji,getDangDayTianShu(time.nian,time.yue))
const days = getDangDayTianShu(time.nian,time.yue)



module.exports = {
   time,
   arr,
   days,
   shanggeDays,
   getArrday,
   xiageDays,
   getDangQianRiQi,
   formatDate,
   formatDatetime,
};

  